<script setup>
import {
    Edit,
    Delete
} from '@element-plus/icons-vue'
import { ref } from 'vue'
const warehousing = ref([

])
//声明一个异步函数
import {getWarehousingService,upDateWarehousingService} from '@/api/warehousing.js'
import { ElMessage } from 'element-plus'
const warehousingList = async()=>{
    let result = await getWarehousingService();
    warehousing.value = result.data;
}
warehousingList();

const dialogVisible = ref(false)

//添加入库数据模型
const warehousingModel = ref({
    storageTime: '',
    licensePlateNumber: '',
    inboundQty: '',
    inboundTonnage: ''
})
//添加出库表单校验
const rules = {
    storageTime: [
        { required: true, message: '请输入入库时间', trigger: 'blur' },
    ],
    licensePlateNumber: [
        { required: true, message: '请输入车牌号', trigger: 'blur' },
    ],
    inboundQty: [
        { required: true, message: '请输入入库件数', trigger: 'blur' },
    ],
    inboundTonnage: [
        { required: true, message: '请输入入库吨数', trigger: 'blur' },
    ]
}
//调用接口添加表单
const upDateWarehousing = async()=>{
    //调用接口
    let result = await upDateWarehousingService(warehousingModel.value);
    ElMessage.success(result.message? result.message:'添加成功')

    //调用获取所有入库数据的函数
    warehousingList();
    dialogVisible.value = false;
}
</script>
<template>
    <el-card class="page-container">
        <template #header>
            <div class="header">
                <span>入库管理</span>
                <div class="extra">
                    <el-button type="primary" @click="dialogVisible = true">添加入库</el-button>
                </div>
            </div>
        </template>
        <el-table :data="warehousing" style="width: 100%">
            <el-table-column label="序号" width="100" type="index"> </el-table-column>
            <el-table-column label="入库时间" prop="storageTime"></el-table-column>
            <el-table-column label="车牌号" prop="licensePlateNumber"></el-table-column>
            <el-table-column label="入库件数" prop="inboundQty"></el-table-column>
            <el-table-column label="入库吨数" prop="inboundTonnage"></el-table-column>
 
            <template #empty>
                <el-empty description="没有数据" />
            </template>
        </el-table>
        <!-- 添加分类弹窗 -->
        <el-dialog v-model="dialogVisible" title="添加入库" width="30%">
            <el-form :model="warehousingModel" :rules="rules" label-width="100px" style="padding-right: 30px">
                <el-form-item label="入库时间" prop="storageTime">
                    <el-date-picker v-model="warehousingModel.storageTime" type="date" placeholder="选择日期" style="width: 80%"></el-date-picker>
                </el-form-item>
                <el-form-item label="车牌号" prop="licensePlateNumber">
                    <el-input v-model="warehousingModel.licensePlateNumber" minlength="1" maxlength="15"></el-input>
                </el-form-item>
                <el-form-item label="入库件数" prop="inboundQty">
                    <el-input v-model="warehousingModel.inboundQty" minlength="1" maxlength="15"></el-input>
                </el-form-item>
                <el-form-item label="入库吨数" prop="inboundTonnage">
                    <el-input v-model="warehousingModel.inboundTonnage" minlength="1" maxlength="15"></el-input>
                </el-form-item>
            </el-form>
            <template #footer>
                <span class="dialog-footer">
                    <el-button @click="dialogVisible = false">取消</el-button>
                    <el-button type="primary" @click="upDateWarehousing"> 确认 </el-button>
                </span>
            </template>
        </el-dialog>        
    </el-card>
</template>

<style lang="scss" scoped>
.page-container {
    min-height: 100%;
    box-sizing: border-box;

    .header {
        display: flex;
        align-items: center;
        justify-content: space-between;
    }
}
</style>